﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace CodeGen
{
    public class ClsNetInfo
    {
        // Fields
        public string Address;
        private bool isSet = false;
        public string Key;
        public int KeyCiper;
        public int KeyLen;
        public int Port;
        public int Protocol;

        // Methods
        public void initFromFile(string f_name)
        {
            if (!this.isSet)
            {
                StreamReader reader = File.OpenText(f_name);
                while (reader.Peek() >= 0)
                {
                    this.setDataMember(reader.ReadLine());
                }
                reader.Close();
                this.isSet = true;
            }
        }

        static string Right(string s, int count)
        {
            string newString = String.Empty;
            if (s != null && count > 0)
            {
                int startIndex = s.Length - count;
                if (startIndex > 0)
                    newString = s.Substring(startIndex, count);
                else
                    newString = s;
            }
            return newString;
        }

        private void setDataMember(string line_in)
        {
            long num = line_in.IndexOf("=");
            if (num != -1)
            {
                string str2 = line_in.Split('=')[1].Trim();
                string str3 = line_in.Split('=')[0].Trim();

                switch (str3)
                {
                    case "Protocol":
                        this.Protocol = Convert.ToInt32(str2);
                        break;
                    case "Address":
                        this.Address = str2;
                        break;
                    case "Port":
                        this.Port = Convert.ToInt32(str2);
                        break;
                    case "KeyCiper":
                        this.KeyCiper = Convert.ToInt32(str2);
                        break;
                    case "Key":
                        this.Key = str2;
                        break;
                    case "KeyLen":
                        this.KeyLen = Convert.ToInt32(str2);
                        break;
                    default:
                        break;
                }
            }
        }
    }
}
